package com.rwy.dao;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import com.rwy.dto.device.EmployeeDTO;
import com.rwy.dto.device.FaultCategoryDTO;
import com.rwy.dto.device.HandleFaultDeviceItemDTO;
import com.rwy.dto.device.HandleFaultRecordDTO;
import com.rwy.dto.device.HandleFaultTaskDTO;

@Mapper
public interface HandleFaultDaoMapper {
	
	@Select("SELECT faultCategoryID as categoryId ,parentID, categoryName , categoryType"
			+ "  FROM device_fault_category WHERE categoryType IN(1,2) and isEnabled =1 ")
	public List<FaultCategoryDTO> getFaultCategoryList();

	@SelectProvider(type = HandleFaultProvider.class, method = "adviceFaultTaskForEmployee")
	public List<HandleFaultTaskDTO> adviceFaultTaskForEmployee();
	
	@SelectProvider(type = HandleFaultProvider.class, method = "createFaultTask")
	public void createFaultTask();
	
	@SelectProvider(type = HandleFaultProvider.class, method = "createAdviceTask")
	public void createAdviceTask();
	
	@SelectProvider(type = HandleFaultProvider.class, method = "updateDisconnectTeriminal")
	public void updateDisconnectTeriminal();
	
	@SelectProvider(type = HandleFaultProvider.class, method = "createDisconnectTeriminal")
	public void createDisconnectTeriminal();
	
	
	@SelectProvider(type = HandleFaultProvider.class, method = "updateFaultHandling")
	public void updateFaultHandling(@Param("task") HandleFaultTaskDTO task);
	
	@SelectProvider(type = HandleFaultProvider.class, method = "updateHandlAdvice")
	public void updateHandlAdvice(@Param("task") HandleFaultTaskDTO task);
	
	@SelectProvider(type = HandleFaultProvider.class, method = "insertFaultHandlingRecord")
	public void insertFaultHandlingRecord(@Param("record") HandleFaultRecordDTO record);
	
	@SelectProvider(type = HandleFaultProvider.class, method = "getFaultTaskItem")
	public List<HandleFaultDeviceItemDTO> getFaultDeviceTaskItemByParam(@Param("handStatus") Integer handStatus, @Param("employeeID") Integer employeeID, @Param("page")Integer page, @Param("pageSize")Integer pageSize);
	
	@SelectProvider(type = HandleFaultProvider.class, method = "getFaultTaskItemCount")
	public int getFaultDeviceTaskItemCount(@Param("handStatus") Integer handStatus, @Param("employeeID") Integer employeeID);
	
	@SelectProvider(type = HandleFaultProvider.class, method = "getEmployeeByMobile")
	public EmployeeDTO getEmployeeByMobile(@Param("mobile") String mobile);
	
	@SelectProvider(type = HandleFaultProvider.class, method ="getDeviceMessage")
	public HandleFaultDeviceItemDTO getDeviceMessage(@Param("terminalID") Integer terminalID, @Param("handID")Integer handID);
	
	@Select("select a.*, b.employeeID as  adviceEmployID , b.employeeName as  adviceEmployName "
			+ " from device_fault_handing a  INNER JOIN device_fault_handing_advice b  ON a.handID = b.handID "
			+ " where  a.handID=#{handID} and b.employeeID =#{employeeId} ")
	public HandleFaultTaskDTO getFaultDeviceTask(@Param("employeeId") Integer employeeId, @Param("handID") Integer handID);
	
	@Select("select  top 1 *, faultDescIDs AS faultCategoryIDs,maintainRecord AS maintianRecord  from device_fault_handing_record where handID = #{handID} and recordStatus =#{recordStatus} order by handRecordID desc")
	public HandleFaultRecordDTO getHandleReocrdDetail(@Param("recordStatus")Integer recordStatus, @Param("handID") Integer handID);
	
	@SelectProvider(type = HandleFaultProvider.class, method="syncNormalTerminalStatus")
	public void syncNormalTerminalStatus();
	
	
}
